﻿using System;
using System.Xml.Schema;
using System.Xml.Serialization;
using flickr.api.communication;

namespace flickr.api
{
	[Serializable]
	public class PhotoInfo : FlickrObject
	{
	    public PhotoInfo():base(){}
	    public PhotoInfo(FlickrConnection connection) : base(connection){} 
	    
		[XmlAttribute("id", Form=XmlSchemaForm.Unqualified)]
		public string PhotoId;

		[XmlAttribute("secret", Form=XmlSchemaForm.Unqualified)]
		public string Secret;

		[XmlAttribute("server", Form=XmlSchemaForm.Unqualified)]
		public int Server;

		[XmlIgnore()]
		public DateTime DateUploaded
		{
			get { return Utilities.UnixTimestampToDate(dateuploaded); }
		}

		[XmlAttribute("dateuploaded", Form=XmlSchemaForm.Unqualified)]
		public string dateuploaded;

		[XmlAttribute("isfavorite", Form=XmlSchemaForm.Unqualified)]
		public int IsFavourite;

		[XmlAttribute("license", Form=XmlSchemaForm.Unqualified)]
		public int License;

		[XmlElement("owner", Form=XmlSchemaForm.Unqualified)]
		public PhotoInfoOwner Owner;

		[XmlElement("title", Form=XmlSchemaForm.Unqualified)]
		public string Title;

		[XmlElement("description", Form=XmlSchemaForm.Unqualified)]
		public string Description;

		[XmlElement("visibility", Form=XmlSchemaForm.Unqualified)]
		public PhotoInfoVisibility Visibility;

		[XmlElement("permissions", Form=XmlSchemaForm.Unqualified)]
		public PhotoInfoPermissions Permissions;

		[XmlElement("editability", Form=XmlSchemaForm.Unqualified)]
		public PhotoInfoEditability Editability;

		[XmlElement("comments", Form=XmlSchemaForm.Unqualified)]
		public int CommentsCount;

		[XmlElement("notes", Form=XmlSchemaForm.Unqualified)]
		public PhotoInfoNotes Notes;

		[XmlElement("tags", Form=XmlSchemaForm.Unqualified)]
		public PhotoInfoTags Tags;
	
		[XmlElement("exif", Form=XmlSchemaForm.Unqualified)]
		public ExifTag[] ExifTagCollection;

		[XmlElement("dates", Form=XmlSchemaForm.Unqualified)]
		public PhotoDates Dates;

		[XmlIgnore()]
		public string WebUrl
		{
			get { return string.Format("http://www.flickr.com/photos/{0}/{1}/", Owner.UserId, PhotoId); }
		}

		private const string photoUrl = "http://photos{0}.flickr.com/{1}_{2}{3}.jpg";

		[XmlIgnore()]
		public string SquareThumbnailUrl
		{
			get { return string.Format(photoUrl, Server, PhotoId, Secret, "_s"); }
		}

		[XmlIgnore()]
		public string ThumbnailUrl
		{
			get { return string.Format(photoUrl, Server, PhotoId, Secret, "_t"); }
		}

		[XmlIgnore()]
		public string SmallUrl
		{
			get { return string.Format(photoUrl, Server, PhotoId, Secret, "_m"); }
		}

		[XmlIgnore()]
		public string MediumUrl
		{
			get { return string.Format(photoUrl, Server, PhotoId, Secret, ""); }
		}

		[XmlIgnore()]
		public string LargeUrl
		{
			get { return string.Format(photoUrl, Server, PhotoId, Secret, "_b"); }
		}
	}

    public enum PermissionComment
	{
		[XmlEnum("0")]
		Nobody = 0,
		[XmlEnum("1")]
		FriendsAndFamily = 1,
		[XmlEnum("2")]
		ContactsOnly = 2,
		[XmlEnum("3")]
		Everybody = 3
	}

	public enum PermissionAddMeta
	{
		[XmlEnum("0")]
		Owner = 0,
		[XmlEnum("1")]
		FriendsAndFamily = 1,
		[XmlEnum("2")]
		Contacts = 2,
		[XmlEnum("3")]
		Everybody = 3
	}

}